/*
 * PanelTowerSettings.cs
 *
 * Created on January 13, 2008, 5:34 PM
 *
 * Copyright (C) 2007-2008  Hylke van der Schaaf
 * Copyright (C) 2010       Mathijs Miermans
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, in version 3 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

using HexTD.util;

namespace HexTD.tower
{
	public class PanelTowerSettings
	{
		private string[] modes;
		private int mode = 0;
		private Tower t;
		private Context c;
		private bool loading = false;

		public PanelTowerSettings(Context c)
		{
			this.c = c;
		}

		/** Creates new form PanelTowerSettings */
		public PanelTowerSettings(Tower t, Context c)
		{
			this.c = c;
#if PORT
			initComponents();
#endif
			this.t = t;
		}

		public void setModes(string[] modes)
		{
#if PORT
			this.loading = true;
			this.modes = modes;
			this.jComboBox_mode.removeAllItems();
			for (int i = 0; i < this.modes.length; i++) {
				this.jComboBox_mode.addItem(this.modes[i]);
			}
			this.jComboBox_mode.setSelectedIndex(this.mode);
			this.jLabel_mode.setText(this.modes[this.mode]);
			this.loading = false;
#endif
		}

		public void setMode(int m, int v)
		{
#if PORT
			if (m == 1) {
				this.mode = v;
				this.loading = true;
				this.jComboBox_mode.setSelectedIndex(this.mode);
				this.jLabel_mode.setText(this.modes[this.mode]);
				this.loading = false;
				if (t.getMode(1) != v) {
					t.setMode(1, this.mode);
				}
			}
#endif
		}

		public int nextMode(int m)
		{
#if PORT
			if (m == 1) {
				this.mode++;
				if (this.mode >= this.modes.length) {
					this.mode = 0;
				}
				this.loading = true;
				this.jComboBox_mode.setSelectedIndex(this.mode);
				this.jLabel_mode.setText(this.modes[this.mode]);
				this.loading = false;
				t.setMode(1, this.mode);
				return this.mode;
			}
#endif
			return -1;
		}

		public int getMode(int m)
		{
#if PORT
			if (m == 1) {
				return this.mode;
			}
#endif
			return -1;
		}

		public void setEnabled(bool enable)
		{
#if PORT
			this.jComboBox_mode.setVisible(enable);
			this.jLabel_mode.setVisible(!enable);
#endif
		}

		/** This method is called from within the constructor to
		 * initialize the form.
		 * WARNING: Do NOT modify this code. The content of this method is
		 * always regenerated by the Form Editor.
		 */
		// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
		private void initComponents()
		{
#if PORT
			java.awt.GridBagConstraints gridBagConstraints;

			jLabel1 = new javax.swing.JLabel();
			jComboBox_mode = new javax.swing.JComboBox();
			jLabel_mode = new javax.swing.JLabel();

			setLayout(new java.awt.GridBagLayout());

			setBackground(this.c.colors.getColorBackGround());
			setForeground(this.c.colors.getColorForeGround());
			jLabel1.setBackground(this.c.colors.getColorBackGround());
			jLabel1.setForeground(this.c.colors.getColorForeGround());
			jLabel1.setText("Target Mode");
			gridBagConstraints = new java.awt.GridBagConstraints();
			gridBagConstraints.gridx = 0;
			gridBagConstraints.gridy = 0;
			gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
			gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
			gridBagConstraints.weightx = 0.01;
			add(jLabel1, gridBagConstraints);

			jComboBox_mode.setBackground(this.c.colors.getColorBackGround());
			jComboBox_mode.setForeground(this.c.colors.getColorForeGround());
			jComboBox_mode.setModel(new javax.swing.DefaultComboBoxModel(new string[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
			jComboBox_mode.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent evt) {
					jComboBox_modeActionPerformed(evt);
				}
			});

			add(jComboBox_mode, new java.awt.GridBagConstraints());

			jLabel_mode.setBackground(this.c.colors.getColorBackGround());
			jLabel_mode.setForeground(this.c.colors.getColorForeGround());
			jLabel_mode.setText("jLabel2");
			add(jLabel_mode, new java.awt.GridBagConstraints());

#endif
		}// </editor-fold>//GEN-END:initComponents

#if PORT
		private void jComboBox_modeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox_modeActionPerformed
			if (!this.loading) {
				this.mode = this.jComboBox_mode.getSelectedIndex();
				this.c.setMode(this.t, 1, this.mode);
			}
		}//GEN-LAST:event_jComboBox_modeActionPerformed
		// Variables declaration - do not modify//GEN-BEGIN:variables
		private javax.swing.JComboBox jComboBox_mode;
		private javax.swing.JLabel jLabel1;
		private javax.swing.JLabel jLabel_mode;
		// End of variables declaration//GEN-END:variables
#endif
	}
}